package com.itheima.Service.imple;

import com.itheima.Service.DeptService;
import com.itheima.entity.Dept;
import com.itheima.mapper.DeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service//程序启动时，会自动创建该类对象，并交给IOC容器处理(@Service=@Component, 只是用于标识当前逻辑层属于处理类)
// 业务逻辑处理层
public class DeptServiceDao implements DeptService {
    //private DeptDao deptDao=new DeptDaoImpl();
    @Autowired
    private DeptMapper deptmapper;
    public List<Dept> list(){
      //1.调用mapper的方法获取数据
        // 2.返回数据
        List<Dept> depts = deptmapper.list();
       return depts;

    }
    //根据id删除部门
    @Override
    public void delete(Integer id) {
        //调用mapper的删除方法
        deptmapper.delete(id);
    }

    @Override
    public void save(Dept dept) {
        //1.补充基本属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        //2.调用mapper的新增方法
        deptmapper.insert(dept);
    }

    @Override
    public Dept getById(Integer id) {
        //调用mapper的查询方法

        return deptmapper.selectById(id);
    }
    //修改部门
    @Override
    public void update(Dept dept) {
        //1.补充更新时间
        dept.setUpdateTime(LocalDateTime.now());
        //调用mapper层方法
        deptmapper.update(dept);
    }
}
